package cn.edu.cqvie.jdk8.stream2;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class MyComparatorTest {

    public static void main(String[] args) {
        List<String> list = Arrays.asList("nihao", "hello", "world", "welcome");

//        Collections.sort(list,
//                //        Comparator.comparingInt(String::length)
//                //        (a, b) -> a.length() - b.length()
//                (a, b) -> b.length() - a.length()
//        );

        Collections.sort(list, Comparator.comparingInt(String::length).reversed());

//        list.sort(Comparator.comparingInt(String::length).reversed());

        //不能自动推断类型的时候需要手动指定
//        list.sort(Comparator.comparingInt((String item) -> item.length()).reversed());

        // thenComparing 第一个比较器不能确定顺序才使用第二个
//        list.sort(Comparator.comparingInt(String::length).thenComparing(String.CASE_INSENSITIVE_ORDER));

//        list.sort(Comparator.comparingInt(String::length).thenComparing(Comparator.comparing(String::toLowerCase)));

//        list.sort(Comparator.comparingInt(String::length).thenComparing(Comparator.comparing(String::toLowerCase, Comparator.reverseOrder())));

//        list.sort(Comparator.comparingInt(String::length).reversed().thenComparing(String::toLowerCase, Comparator.reverseOrder()));

        list.sort(Comparator.comparingInt(String::length).reversed()
                .thenComparing(Comparator.comparing(String::toLowerCase, Comparator.reverseOrder()))
                //没有发挥作用，前面两个已经能够确定排序了
                .thenComparing(Comparator.reverseOrder())
                );
        System.out.println(list);
    }
}
